﻿/******************************************************************
** 文 件 名: Bu_AuditTable_FGW_List.aspx.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2013/3/14 20:12:00
** 描    述: 资金支付汇总表-发改委返回列表页面
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseLibrary;
using Honestysoft.BaseObject;
using Honestysoft.BaseLibrary.ExceptionHandling;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
	public partial class Bu_AuditTable_FGW_List : BasePage
	{	
		protected override void Page_Load(object sender, EventArgs e)
        {
			base.Page_Load(sender, e);
            if (!IsPostBack)
            {		
				AspNetPager1.PageSize = Globals.PageSize;
				BindControl();
                Bind();
            }
        }
		/// <summary>
        /// 绑定页面控件。
        /// </summary>
		private void BindControl()
		{
		}
		/// <summary>
        /// 设置弹出窗体大小
		/// 基类中已自动做控制。默认宽度800，高度600
        /// </summary>
		protected override void SetDialogSize()
		{
			//base.SetDialogSize();
			//重载宽度，高度
            ModalDialogSize.EditHeight = 600;
            ModalDialogSize.EditWidth = 800;
            ModalDialogSize.ViewHeight = 600;
            ModalDialogSize.ViewWidth = 800;
		}
		/// <summary>
        /// 根据权限控制页面按钮.
        /// 基类中已自动做控制。
        /// </summary>
        protected override void ButtonSetting()
        {
            base.ButtonSetting();
            //使用PageSecurity检查权限
            if (PageSecurity.Add)
            {
                btnAdd.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Audit/Bu_AuditTable_FGW_Edit.aspx?FunctionID="+FunctionID+ "'," + ModalDialogSize.EditWidth + ", " + ModalDialogSize.EditHeight + ", '新增资金支付汇总表');return false;");
            }
        }
		/// <summary>
        /// 得到查询参数
        /// </summary>
        /// <returns>查询参数</returns>
		private QueryParameters GetQueryParameters()
		{
			QueryParameters queryParameters = new QueryParameters();
			if(numBatchNo.Text.Trim().Length > 0)
			{
				queryParameters.Add("BatchNo",numBatchNo.Text,QueryParameters.OperatorType.Equal);
			}
			return queryParameters;
		}
		/// <summary>
        /// 得到排序参数
        /// </summary>
        /// <returns></returns>
		private OrderParameters GetOrderParameters()
		{
			OrderParameters orderParameters = new OrderParameters();
            orderParameters.Add("BatchNo", OrderParameters.OrderDirection.Desc);
            orderParameters.Add("Counter");
			//添加排序列
			return orderParameters;
		}
		/// <summary>
        /// 绑定列表
        /// </summary>
		private void Bind()
        {
			QueryParameters queryParameters = GetQueryParameters();
			OrderParameters orderParameters = GetOrderParameters();
			BaseBusinessLogic<Bu_AuditTable_FGW> baseLogic = new BaseBusinessLogic<Bu_AuditTable_FGW>();
            int pageCount = 0, recordCount = 0;
            DataTable dtList = baseLogic.GetTablePaging(queryParameters, orderParameters, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out pageCount, out recordCount);
            dtList.Columns.Add("IsLast", typeof(Boolean));
            Dictionary<int, int> dicBatchMaxCounter = new Dictionary<int, int>();
            int batchNo=0,maxCounter=0;
            foreach (DataRow dr in dtList.Rows)
            {
                batchNo=Convert.ToInt32(dr["BatchNo"]);
                maxCounter=Convert.ToInt32(dr["Counter"]);
                if (!dicBatchMaxCounter.ContainsKey(batchNo))
                {
                    dicBatchMaxCounter.Add(batchNo, maxCounter);
                }
                else
                {
                    if (maxCounter > dicBatchMaxCounter[batchNo])
                    {
                        dicBatchMaxCounter[batchNo] = maxCounter;
                    }
                }
            }
            foreach (DataRow dr in dtList.Rows)
            {
                batchNo = Convert.ToInt32(dr["BatchNo"]);
                maxCounter = Convert.ToInt32(dr["Counter"]);
                dr["IsLast"] = (dicBatchMaxCounter[batchNo] == maxCounter);
            }
            AspNetPager1.RecordCount = recordCount;
            rptList.DataSource = dtList;
            rptList.DataBind();
        }


        protected string GetCheckBox(string dataId, bool isLast)
        {
            //<input type="checkbox" name="chkID" id="chk<%# DataBinder.Eval(Container.DataItem,"ID") %>"  value="<%# DataBinder.Eval(Container.DataItem,"ID") %>" >
            string script = "";
            if (isLast)
            {
                script += "<input type=\"checkbox\" name=\"chkID\" id=\"chk" + dataId + "\" value=\"" + dataId + "\">";
            }
            return script;
        }
		/// <summary>
        /// 得到表格行操作按钮脚本
        /// </summary>
        /// <param name="dataId">记录ID</param>
        /// <returns>操作按钮脚本</returns>
        protected string GetButtonScript(string dataId,bool isLast,string batchNo,string counter)
        {
			string script = "";
            if (PageSecurity.Edit)
            {
                script += ScriptHelper.LinkButton.GetGridEditButton(Globals.Home + "Module/Audit/Bu_AuditTable_FGW_Edit.aspx", "修改资金支付汇总表-发改委返回", ModalDialogSize.EditWidth, ModalDialogSize.EditHeight, dataId, FunctionID);
            }
            if (PageSecurity.View)
            {
                if (script.Length > 0) { script += "&nbsp;&nbsp;"; }
                script += ScriptHelper.LinkButton.GetGridImageButton("ViewReport('" + dataId + "','" + batchNo + "','" + ChineseNum.GetChineseNum(counter) + "');", ScriptHelper.Image.GetUrl(ScriptHelper.Image.ImageType.View), "点击查看第" + batchNo + "批第（" + ChineseNum.GetChineseNum(counter) + "）次资金支付汇总表", "");
            }
            if (PageSecurity.Delete && isLast)
            {
                if (script.Length > 0) { script += "&nbsp;&nbsp;"; }
                script += ScriptHelper.LinkButton.GetGridDeleteButton(dataId, btnDelete.ClientID);
            }
            else
            {
                script += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
            }
            return script;
        }
		
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }
		
		protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            Bind();
        }
		/// <summary>
        /// 得到选中的记录ID集合
        /// </summary>
        /// <returns></returns>
        private string[] GetSelectedRowKeys()
        {
            string strId = Request["chkID"]+"";
            if (string.IsNullOrEmpty(strId)) { return null; }
            return strId.Split(',');
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
			try
            {
                string[] arrId = GetSelectedRowKeys();
                BaseBusinessLogic<Bu_AuditTable_FGW> baseLogic = new BaseBusinessLogic<Bu_AuditTable_FGW>();
                baseLogic.DeleteByKey(arrId);
                ScriptHelper.Window.Alert("删除成功！");
                Bind();
            }
            catch (Honestysoft.BaseLibrary.ExceptionHandling.BaseException bex)
            {
                ExceptionHelper.ExceptionDistribute(bex, false);
                ScriptHelper.Window.Alert(bex.Message);
            }
            catch (Exception ex)
            {
                ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.Alert("删除失败！系统发生了未知错误！");
            }
        }
	}
}
